package wx.controls
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	[Event(name="change",type="flash.events.Event")]
	
	/**
	 * 单选按钮群组 
	 */	
	public class RadioGroup extends EventDispatcher
	{
		
		public var items:Vector.<Radio>;		
		public function RadioGroup()
		{
			if(items==null)items = new <Radio>[];
		}

		/**
		 * 
		 * @return 
		 * 取选中值
		 * 
		 */		
		public function get selectValue():Object
		{
			var _selectValue:Object;
			if(items.length>0){
				for each(var i:Radio in items){
					if(i.selected){
						_selectValue = i.value;	
						break;
					}
				}				
			}		
			return _selectValue;
		}

		/**
		 * 
		 * @param value
		 * 设置选中值
		 * 
		 */		
		public function set selectValue(value:Object):void
		{
			if(items.length>0){
				for each(var i:Radio in items){
					if(i.value!=null){
						if(i.value == value) i.selected = true; 
						else i.selected = false;
					}else{
						if(i.label == value) i.selected = true;
						else i.selected = false;
					}
				}
				dispatchEvent(new Event(Event.CHANGE));
			}
		}
		

	}
}